package com.yxhl.zoume.core.func.map.ui.adapter;


import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.yxhl.zoume.R;

import java.util.List;

/**
 * Created by sugarya on 16/4/14.
 */
public class SearchSpinnerAdapter extends BaseAdapter {

    private List<String> cities;
    private Context context;

    public SearchSpinnerAdapter(Context context, List<String> cities) {
        this.cities = cities;
        this.context = context;
    }

    @Override
    public int getCount() {
        return cities.size();
    }

    @Override
    public Object getItem(int position) {
        return cities.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_search_spinner, parent, false);
        }
        TextView titleTv = (TextView) convertView.findViewById(R.id.tv_item_spinner_title);

        String s = cities.get(position);
        if (!TextUtils.isEmpty(s)) {
            titleTv.setText(s);
        }

        return convertView;
    }
}
